<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<rich:panel header="#{msg.schedule_control}" rendered="#{scheduleManageBean.status == 'SELECT'}">
	<br />

	<rich:panel header="#{msg.search_criteria}">
		<h:outputText value="#{msg.search_criteria}" />
		<h:outputText value=": " />
		<h:outputText value="#{scheduleManageBean.searchDescription}" />
		
		<br />
		<br />
		
		<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;" 
				value="#{msg.back}" action="#{scheduleManageBean.init}" 
				render="@form" />
			
		<h:outputText value="&#160;" rendered="#{not empty scheduleManageBean.clickedMachineOptions}" />		
		<h:outputText value="&#160;" rendered="#{not empty scheduleManageBean.clickedMachineOptions}"/>
			
		<a4j:commandButton id="createPane_btn" value="#{msg.create}"
			action="#{scheduleManageBean.newItem}"
			styleClass="buttonClass" style="font-size: 16px;"
			execute="@this" render="@form"
			oncomplete="#{rich:component('createPane')}.show();" >									
		</a4j:commandButton>
				
	</rich:panel>

	<br />

	<rich:panel header="#{msg.schedule_list}">

		<h:outputText value="#{msg.no_record_found}" rendered="#{empty scheduleManageBean.scheduleTerms}" />
			
		<a4j:commandLink style="font-size: 12px;"
			value="#{msg.select_all}" rendered="#{not empty scheduleManageBean.scheduleTerms}"
			action="#{scheduleManageBean.selectAllSchedule}" render="@form"/>
				
		<h:outputText value="&#160;" rendered="#{not empty scheduleManageBean.scheduleTerms}" />		
		<h:outputText value="&#160;" rendered="#{not empty scheduleManageBean.scheduleTerms}"/>
				
		<a4j:commandLink style="font-size: 12px;" 
			value="#{msg.clear}" rendered="#{not empty scheduleManageBean.scheduleTerms}"
			action="#{scheduleManageBean.clearAllSchedule}" render="@form"/>	
											
		<br />

		<rich:extendedDataTable id="dataTable" width="100%" rows="15" frozenColumns="1" 
			value="#{scheduleManageBean.scheduleTerms}" var="scheduleTerm" iterationStatusVar="it">

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.index_logo}" />
				</f:facet>
				
				<h:selectBooleanCheckbox value="#{scheduleManageBean.deleteScheduleIdMap[scheduleTerm.id]}" onclick="updateDeleteSchedule('#{scheduleTerm.id}')">													
					<a4j:ajax event="click" render="@form" listener="#{scheduleManageBean.updateDeleteScheduleIdList}" />					
				</h:selectBooleanCheckbox>	
								
				
			</rich:column>

			<rich:column width="180px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.machine_name}" />
				</f:facet>
				<h:outputText value="#{scheduleTerm.machine.machineName}" />
			</rich:column>

			<rich:column width="80px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.time}" />
				</f:facet>
				<h:outputText value="#{scheduleTerm.scheduleHour}" />
				<h:outputText value=":" />
				<h:outputText value="#{scheduleTerm.scheduleMin}" />
			</rich:column>

			<rich:column width="100px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.start_option}" />
				</f:facet>
				<h:outputText value="#{msg.start_on}" rendered="#{scheduleTerm.start}" />
				<h:outputText value="#{msg.start_off}" rendered="#{!scheduleTerm.start}" />
			</rich:column>

			<rich:column width="80px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.fan_speed}" />
				</f:facet>
				<h:outputText value="#{msg.fan_speed_auto}" rendered="#{scheduleTerm.fanSpeed == 0}" />
				<h:outputText value="#{msg.fan_speed_high}" rendered="#{scheduleTerm.fanSpeed == 1}" />
				<h:outputText value="#{msg.fan_speed_mid}" rendered="#{scheduleTerm.fanSpeed == 2}" />
				<h:outputText value="#{msg.fan_speed_low}" rendered="#{scheduleTerm.fanSpeed == 3}" />

			</rich:column>

			<rich:column width="100px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.temperature}(#{msg.celsius})" />
				</f:facet>
				<h:outputText value="#{scheduleTerm.temperature}" />

			</rich:column>

			<rich:column width="100px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.minimum_temperature}(#{msg.celsius})" />
				</f:facet>
				<h:outputText value="#{scheduleTerm.minimumTemperature}" />

			</rich:column>

			<rich:column width="100px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.key_lock}" />
				</f:facet>
				<h:outputText value="#{msg.key_lock_no_lock}" rendered="#{scheduleTerm.keyLock == 0}" />
				<h:outputText value="#{msg.key_lock_fan_speed_only}" rendered="#{scheduleTerm.keyLock == 1}" />

			</rich:column>

			<rich:column width="80px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.status}" />
				</f:facet>
				<h:outputText value="Y" rendered="#{scheduleTerm.active}" />
				<h:outputText value="N" rendered="#{!scheduleTerm.active}" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.monday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execMon}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.tuesday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execTue}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.wednesday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execWed}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.thusday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execThu}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.friday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execFri}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.saturday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execSat}" disabled="true" />
			</rich:column>

			<rich:column width="40px" style="text-align: center;">
				<f:facet name="header">
					<h:outputText style="color:#FFFFFF" styleClass="tableTitle" value="#{msg.sunday}" />
				</f:facet>
				<h:selectBooleanCheckbox value="#{scheduleTerm.execSun}" disabled="true" />
			</rich:column>

			<rich:column width="50px" rendered="#{sec:ifAnyGranted('ROLE_ADMIN, ROLE_SUPERVISOR')}">
				<f:facet name="header">
					<h:outputText value="#{msg.edit}" />
				</f:facet>
				<a4j:commandLink style="border:none;" execute="@this" render="@none" oncomplete="#{rich:component('deletePane')}.show()">
					<h:graphicImage library="images" name="icons/delete.gif" alt="delete" />
					<a4j:param value="#{scheduleTerm.id}" assignTo="#{scheduleManageBean.selectedScheduleTermId}" />
				</a4j:commandLink>


				<a4j:commandLink style="border:none;" render="editPane" execute="@this" action="#{scheduleManageBean.selectItem}" oncomplete="#{rich:component('editPane')}.show()">
					<h:graphicImage library="images" name="icons/edit.gif" alt="edit" />
					<a4j:param value="#{scheduleTerm.id}" assignTo="#{scheduleManageBean.selectedScheduleTermId}" />

				</a4j:commandLink>

			</rich:column>
			
			<f:facet name="footer">
            	<rich:dataScroller />
            </f:facet>
            
		</rich:extendedDataTable>
		
		<br />
		
		<a4j:commandButton id="deleteAllPane_btn" rendered="#{sec:ifAnyGranted('ROLE_ADMIN, ROLE_SUPERVISOR')}" 
			value="#{msg.delete}" styleClass="buttonClass" style="font-size: 16px;"			
			oncomplete="#{rich:component('deleteAllPane')}.show();" >									
		</a4j:commandButton>

	</rich:panel>
	
	<a4j:jsFunction name="updateDeleteSchedule"> 
    	<a4j:param name="param1" assignTo="#{scheduleManageBean.deleteScheduleId}"/> 		
	</a4j:jsFunction>	 	
	
	<a4j:jsFunction name="remove" action="#{scheduleManageBean.remove}" 
					render="dataTable" execute="@this"
            		oncomplete="#{rich:component('deletePane')}.hide();" />
            		
    <a4j:jsFunction name="removeAll" action="#{scheduleManageBean.deleteAllSchedule}" 
					render="dataTable" execute="@this"
            		oncomplete="#{rich:component('deleteAllPane')}.hide();" />        		
            		
				<rich:popupPanel id="deletePane" autosized="true">
					<f:facet name="header">
            			<h:outputText value="#{msg.delete}" />
        			</f:facet>
					<h:outputText value="#{msg.delete_confirm_message}" styleClass="inputText" style="font-size: 16px;" />		            
		            <a4j:commandButton styleClass="buttonClass" style="font-size: 16px;" 
		            	value="#{msg.cancel}" onclick="#{rich:component('deletePane')}.hide(); return false;" />
		            <a4j:commandButton styleClass="buttonClass" style="font-size: 16px;"
		            	value="#{msg.delete}" onclick="remove(); return false;" />
		        </rich:popupPanel>	
		        
	<rich:popupPanel id="deleteAllPane" autosized="true">
		<f:facet name="header">
			<h:outputText value="#{msg.delete}" />
		</f:facet>
		
		<h:outputText value="#{msg.delete_confirm_message}" styleClass="inputText" style="font-size: 16px;" />		            
		
		<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;" 
			value="#{msg.cancel}" onclick="#{rich:component('deleteAllPane')}.hide(); return false;" />
			
		<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;"
			value="#{msg.delete}" onclick="removeAll(); return false;" />
	</rich:popupPanel>			        		
								
		        <rich:popupPanel header="#{msg.edit}" id="editPane"  width="450" height="420" 
		        	autosized="true" domElementAttachment="parent">
		        	
		        	<f:facet name="controls">
			            <h:outputLink value="#" onclick="#{rich:component('editPane')}.hide(); return false;" styleClass="inputText">			                
			                X
			            </h:outputLink>
			        </f:facet>
		        	
		        	<table>
						<tr>
							<td>
								<h:outputText value="#{msg.time}" styleClass="outputText" style="font-size: 16px;"/>
								<h:outputText value="&#160;" />	
							</td>
							<td>
								<h:selectOneMenu styleClass="short_selectClass2"			                			
									value="#{scheduleManageBean.editItem.scheduleHour}" >	
									<f:selectItems value="#{scheduleManageBean.hourOptions}" />														
								</h:selectOneMenu>	
								<h:outputText value=":" styleClass="outputText" style="font-size: 16px;"/>
								<h:selectOneMenu styleClass="short_selectClass2"			                			
									value="#{scheduleManageBean.editItem.scheduleMin}" >	
									<f:selectItems value="#{scheduleManageBean.minuteOptions}" />														
								</h:selectOneMenu>
							</td>
						</tr>
																	
						<tr>
							<td>
								<h:outputText value="#{msg.start_option}" styleClass="outputText" style="font-size: 16px;" />
								<h:outputText value="&#160;" />	
							</td>
							<td>
								<h:selectOneMenu 
									styleClass="selectClass" value="#{scheduleManageBean.editItem.start}" >									
									<f:selectItem itemLabel="#{msg.start_on}" itemValue="#{true}" />
									<f:selectItem itemLabel="#{msg.start_off}" itemValue="#{false}" />
								</h:selectOneMenu>
							</td>
						</tr>

						<tr>

							<td><h:outputText value="#{msg.fan_speed}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>


							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.fanSpeed}">
									<f:selectItem itemLabel="#{msg.fan_speed_auto}" itemValue="#{0}" />
									<f:selectItem itemLabel="#{msg.fan_speed_high}" itemValue="#{1}" />
									<f:selectItem itemLabel="#{msg.fan_speed_mid}" itemValue="#{2}" />
									<f:selectItem itemLabel="#{msg.fan_speed_low}" itemValue="#{3}" />

								</h:selectOneMenu></td>

						</tr>

						<tr>
							<td><h:outputText value="#{msg.temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.temperature}">
									<f:selectItems value="#{scheduleManageBean.temperatureOptions}" />
								</h:selectOneMenu></td>
						</tr>

						<tr>
							<td><h:outputText value="#{msg.minimum_temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.minimumTemperature}">
									<f:selectItems value="#{scheduleManageBean.minimumTemperatureOptions}" />
								</h:selectOneMenu></td>
						</tr>
						
						<tr>
							<td><h:outputText value="#{msg.key_lock}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td>
								<h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.keyLock}" >									
									<f:selectItem itemLabel="#{msg.key_lock_no_lock}" itemValue="#{0}" />
									<f:selectItem itemLabel="#{msg.key_lock_fan_speed_only}" itemValue="#{1}" />									
								</h:selectOneMenu>	
							</td>
						</tr>

						<tr>
							<td><h:outputText value="#{msg.status}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.active}">
									<f:selectItem itemLabel="Y" itemValue="#{true}" />
									<f:selectItem itemLabel="N" itemValue="#{false}" />
								</h:selectOneMenu></td>
						</tr>

						<tr>
							<td><h:outputText value="#{msg.schedule}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td>#{msg.monday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execMon}" /> #{msg.tuesday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execTue}" />
								#{msg.wednesday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execWed}" />
							</td>
						</tr>

						<tr>
							<td></td>
							<td>#{msg.thusday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execThu}" /> #{msg.friday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execFri}" />
								#{msg.saturday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execSat}" />
							</td>
						</tr>

						<tr>
							<td></td>
							<td>#{msg.sunday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execSun}" />
							</td>
						</tr>
						
						<tr>
							<td colspan="2" align="right">
								<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;" 
									value="#{msg.save}" action="#{scheduleManageBean.update}" render="@form" execute="editPane"
		                			oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
		            			<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;" 
		            				value="#{msg.cancel}" onclick="#{rich:component('editPane')}.hide(); return false;" />
							</td>						
						</tr>
						
					</table>
						
				</rich:popupPanel>
				
				<rich:popupPanel header="#{msg.create}" id="createPane"  width="450" height="420" 
		        	autosized="true" domElementAttachment="parent">
		        	
		        	<f:facet name="controls">
			            <h:outputLink value="#" onclick="#{rich:component('createPane')}.hide(); return false;" styleClass="inputText">			                
			                X
			            </h:outputLink>
			        </f:facet>
		        	
		        	<table>
						<tr>
							<td>
								<h:outputText value="#{msg.time}" styleClass="outputText" style="font-size: 16px;"/>
								<h:outputText value="&#160;" />	
							</td>
							<td>
								<h:selectOneMenu styleClass="short_selectClass2"			                			
									value="#{scheduleManageBean.editItem.scheduleHour}" >	
									<f:selectItems value="#{scheduleManageBean.hourOptions}" />														
								</h:selectOneMenu>	
								<h:outputText value=":" styleClass="outputText" style="font-size: 16px;"/>
								<h:selectOneMenu styleClass="short_selectClass2"			                			
									value="#{scheduleManageBean.editItem.scheduleMin}" >	
									<f:selectItems value="#{scheduleManageBean.minuteOptions}" />														
								</h:selectOneMenu>
							</td>
						</tr>
																	
						<tr>
							<td>
								<h:outputText value="#{msg.start_option}" styleClass="outputText" style="font-size: 16px;" />
								<h:outputText value="&#160;" />	
							</td>
							<td>
								<h:selectOneMenu 
									styleClass="selectClass" value="#{scheduleManageBean.editItem.start}" >									
									<f:selectItem itemLabel="#{msg.start_on}" itemValue="#{true}" />
									<f:selectItem itemLabel="#{msg.start_off}" itemValue="#{false}" />
								</h:selectOneMenu>
							</td>
						</tr>

						<tr>

							<td><h:outputText value="#{msg.fan_speed}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>


							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.fanSpeed}">
									<f:selectItem itemLabel="#{msg.fan_speed_auto}" itemValue="#{0}" />
									<f:selectItem itemLabel="#{msg.fan_speed_high}" itemValue="#{1}" />
									<f:selectItem itemLabel="#{msg.fan_speed_mid}" itemValue="#{2}" />
									<f:selectItem itemLabel="#{msg.fan_speed_low}" itemValue="#{3}" />

								</h:selectOneMenu></td>

						</tr>

						<tr>
							<td><h:outputText value="#{msg.temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.temperature}">
									<f:selectItems value="#{scheduleManageBean.temperatureOptions}" />
								</h:selectOneMenu></td>
						</tr>

						<tr>
							<td><h:outputText value="#{msg.minimum_temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.minimumTemperature}">
									<f:selectItems value="#{scheduleManageBean.minimumTemperatureOptions}" />
								</h:selectOneMenu></td>
						</tr>
						
						<tr>
							<td><h:outputText value="#{msg.key_lock}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td>
								<h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.keyLock}" >									
									<f:selectItem itemLabel="#{msg.key_lock_no_lock}" itemValue="#{0}" />
									<f:selectItem itemLabel="#{msg.key_lock_fan_speed_only}" itemValue="#{1}" />									
								</h:selectOneMenu>	
							</td>
						</tr>


						<tr>
							<td><h:outputText value="#{msg.status}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td><h:selectOneMenu styleClass="selectClass" value="#{scheduleManageBean.editItem.active}">
									<f:selectItem itemLabel="Y" itemValue="#{true}" />
									<f:selectItem itemLabel="N" itemValue="#{false}" />
								</h:selectOneMenu></td>
						</tr>

						<tr>
							<td><h:outputText value="#{msg.schedule}" styleClass="outputText" style="font-size: 16px;" /> <h:outputText value="&#160;" /></td>
							<td>#{msg.monday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execMon}" /> #{msg.tuesday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execTue}" />
								#{msg.wednesday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execWed}" />
							</td>
						</tr>

						<tr>
							<td></td>
							<td>#{msg.thusday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execThu}" /> #{msg.friday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execFri}" />
								#{msg.saturday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execSat}" />
							</td>
						</tr>

						<tr>
							<td></td>
							<td>#{msg.sunday}<h:selectBooleanCheckbox value="#{scheduleManageBean.editItem.execSun}" />
							</td>
						</tr>
						
						<tr>
							<td colspan="2" align="right">
								<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;"
									value="#{msg.create}" action="#{scheduleManageBean.create}" render="@form" execute="createPane"
		                			oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('createPane')}.hide();}" />
		            			<a4j:commandButton styleClass="buttonClass" style="font-size: 16px;"
		            				value="#{msg.cancel}" onclick="#{rich:component('createPane')}.hide(); return false;" />
							</td>	
							<td></td>					
						</tr>
						
					</table>
						
				</rich:popupPanel>

</rich:panel>
</html>